package com.example.anpapi.entity.po.novelmodel.Novel;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum NovelVisibility {
    PUBLIC("PUBLIC", "公开"),
    PRIVATE("PRIVATE", "私密"),
    FRIENDS_ONLY("FRIENDS_ONLY", "仅好友");

    @EnumValue
    private final String code;

    @JsonValue
    private final String description;

    NovelVisibility(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     */
    public static NovelVisibility getByCode(String code) {
        for (NovelVisibility visibility : values()) {
            if (visibility.getCode().equals(code)) {
                return visibility;
            }
        }
        return PUBLIC;
    }

    @Override
    public String toString() {
        return this.code;
    }
}

